package com.nuaa.yupicturebackend.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.nuaa.yupicturebackend.common.BaseResponse;
import com.nuaa.yupicturebackend.common.ResultUtils;
import com.nuaa.yupicturebackend.utils.WorkdayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author: ortonzhu
 * @data 2025年01月13日 15:36
 * @Description
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {
    public static void main(String[] args) {
        // 指定自定义日期格式
        String dateStr = "2025-01-02 12:00:00";
        String formatPattern = "yyyy-MM-dd HH:mm:ss";
        // 使用 LocalDateTimeUtil.parse 方法并传入自定义格式
        LocalDateTime targetDate = LocalDateTimeUtil.parse(dateStr, formatPattern);

        // 调用 getLastWorkday 方法获取上一个工作日
        LocalDateTime lastWorkday = WorkdayUtils.getLastWorkday(targetDate);
        // 打印结果
        System.out.println("上一个工作日：" + LocalDateTimeUtil.format(lastWorkday, "yyyy-MM-dd"));

    }

    @GetMapping("/getLastWorkday")
    public BaseResponse<LocalDateTime> getLastWorkday(@RequestParam("date") String date) {
        String formatPattern = "yyyy-MM-dd";
        // 使用 LocalDateTimeUtil.parse 方法并传入自定义格式
        LocalDateTime targetDate = LocalDateTimeUtil.parse(date, formatPattern);
        LocalDateTime lastWorkday = WorkdayUtils.getLastWorkday(targetDate);
        return ResultUtils.success(lastWorkday);
    }

    @GetMapping("/getLastWorkday2")
    public BaseResponse<LocalDateTime> getLastWorkday2(@RequestParam("date") String date) {
        String formatPattern = "yyyy-MM-dd";
        // 使用 LocalDateTimeUtil.parse 方法并传入自定义格式
        LocalDateTime targetDate = LocalDateTimeUtil.parse(date, formatPattern);
        LocalDateTime lastWorkday = WorkdayUtils.getLastWorkday(targetDate);
        return ResultUtils.success(lastWorkday);
    }

    @GetMapping("/getBoleCode")
    public BaseResponse<String> getBoleCode(@RequestParam("number") String number) {
        System.out.println("number:" + number);
        return ResultUtils.success(number);
    }
}
